import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class test {
    public static void main(String[] args) {


        List<String> list = getList();
        // 用于按日期分组存储每个国家的奖牌数
        Map<String, Map<String, Integer>> countryDateMedalMap = new HashMap<>();
        // 用于存储所有的日期，方便后续排序
        List<String> dates = new ArrayList<>();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        SimpleDateFormat dateSdf = new SimpleDateFormat("yyyy-MM-dd");

        for (String item : list) {
            String[] parts = item.split(";");
            String country = parts[0];
            String timeStr = parts[1];

            try {
                Timestamp timestamp = new Timestamp(sdf.parse(timeStr).getTime());
                String date = dateSdf.format(timestamp);

                // 如果日期不在 dates 列表中，就添加进去
                if (!dates.contains(date)) {
                    dates.add(date);
                }

                // 如果国家不在 countryDateMedalMap 中，就初始化对应的 Map
                if (!countryDateMedalMap.containsKey(country)) {
                    countryDateMedalMap.put(country, new HashMap<>());
                }

                Map<String, Integer> dateMedalMap = countryDateMedalMap.get(country);
                // 统计该国家在该日期的奖牌数（每次加1）
                dateMedalMap.put(date, dateMedalMap.getOrDefault(date, 0) + 1);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        // 对日期进行从小到大排序
        Collections.sort(dates, new Comparator<String>() {
            @Override
            public int compare(String date1, String date2) {
                return date1.compareTo(date2);
            }
        });

        // 遍历每个日期，输出每个国家在该日期的奖牌数
        for (String date : dates) {
            System.out.print(date + " ");
            for (String country : countryDateMedalMap.keySet()) {
                Map<String, Integer> dateMedalMap = countryDateMedalMap.get(country);
                int medalCount = dateMedalMap.getOrDefault(date, 0);
                System.out.print(country + ":" + medalCount + " ");
            }
            System.out.println();
        }

        // 计算总奖牌数并输出
        System.out.println("总奖牌数");
        for (String country : countryDateMedalMap.keySet()) {
            Map<String, Integer> dateMedalMap = countryDateMedalMap.get(country);
            int totalMedals = 0;
            for (int count : dateMedalMap.values()) {
                totalMedals += count;
            }
            System.out.println(country + totalMedals);
        }
    }

    static List<String> getList() {
        List<String> list = new ArrayList<>();
        list.add("CHN;2022-01-28 00:00:00;5");
        list.add("CHN;2022-01-30 00:00:00;2");
        list.add("RUS;2022-01-31 00:00:00;3");
        list.add("CHN;2022-01-31 00:00:00;5");
        list.add("USA;2022-01-31 00:00:00;5");
        list.add("IND;2022-01-28 00:00:00;4");
        list.add("RUS;2022-01-28 00:00:00;2");
        list.add("CHN;2022-01-29 00:00:00;5");
        list.add("IND;2022-01-30 00:00:00;4");
        list.add("KR;2022-01-31 00:00:00;5");
        list.add("CHN;2022-02-01 00:00:00;5");
        return list;
    }
}